package com.itheima.controller;

import com.itheima.domain.End;
import com.itheima.domain.Statistics;
import com.itheima.service.BookService;
import com.itheima.service.BooklistService;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户登录和注销Controller
 */
@Controller
@RequestMapping("/shower")
public class BooklistController {


    //这个要在ListRanking里面注解@Service@Transactional
    @Autowired
    private BooklistService booklistService;
    @Autowired
    private BookService bookService;
    /*
   用户登录
    */
    @RequestMapping("/showall")
    public ModelAndView showall(String nature, HttpServletRequest request, Integer pageNum, Integer pageSize) {
        System.out.println(nature);
        End end1 = new End();
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
       PageResult pageResult = booklistService.showall(end1, pageNum, pageSize, nature);
        System.out.println("0");
        PageResult pageResult1=bookService.selectallbook();
        System.out.println("01");
        System.out.println(pageResult1.getRows().size()+"长度在此");


        int i;
//      System.out.println("存在"+pageResult.getRows().size());

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("showall");
        modelAndView.addObject("pageResult", pageResult);
        modelAndView.addObject("pageResult1", pageResult1);
        modelAndView.addObject("pageNum", pageNum);
        modelAndView.addObject("lwb",request.getParameter("lwb"));
        modelAndView.addObject("nature1",nature);
        modelAndView.addObject("gourl", "/user/search");
        return modelAndView;

    }


@RequestMapping("showstatistics")
public ModelAndView showstatistics(HttpServletRequest request, Integer pageNum, Integer pageSize) {

    Statistics statistics=new Statistics();
        if (pageNum == null) {
        pageNum = 1;
        }
        if (pageSize == null) {
        pageSize = 10;
        }
        PageResult pageResult = booklistService.showstatistics(statistics, pageNum, pageSize);
        System.out.println("存在"+pageResult.getRows().size());
        ModelAndView modelAndView = new ModelAndView();
       modelAndView.addObject("pageResult", pageResult);
        modelAndView.setViewName("showstatistics");
        return modelAndView;
        }







        }


